package org.sy.lab.多线程基础._3_同步辅助类._2_CountDownLatch门阀;

import java.util.concurrent.CountDownLatch;

public class Crowdfunding implements Runnable {
	
	private CountDownLatch countDownLatch;
	
	public Crowdfunding(int num) {
		countDownLatch = new CountDownLatch(num);
	}
	
	public void join(String name) {
		
		countDownLatch.countDown();
		System.out.println(name + "参与众筹，还需要数量：" + countDownLatch.getCount());
	}

	@Override
	public void run() {
		System.out.println("众筹开始，需求数量：" + countDownLatch.getCount());
		try {
			countDownLatch.await();
			Thread.sleep(10);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("众筹成功");
	}
}
